package com.bbs.controller;

import com.bbs.dto.LikeDTO;
import com.bbs.dto.Result;
import com.bbs.service.LikeService;
import com.bbs.vo.LikeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/likes")
@Tag(name = "点赞管理", description = "点赞相关的接口")
public class LikeController {
    
    @Autowired
    private LikeService likeService;
    
    @PostMapping
    @Operation(summary = "创建点赞", description = "创建新点赞")
    public Result createLike(@RequestBody LikeDTO likeDTO) {
       return likeService.createLike(likeDTO);
    }
    
    @GetMapping("/{id}")
    @Operation(summary = "获取点赞信息", description = "根据点赞ID获取点赞信息")
    @Parameter(name = "id", description = "点赞ID", required = true)
    public Result getLikeById(@PathVariable Long id) {
        LikeVO likeVO = likeService.getLikeById(id);
        return Result.ok(likeVO);
    }
    
    @GetMapping
    @Operation(summary = "获取所有点赞", description = "获取系统中所有点赞")
    public Result getAllLikes() {
        return Result.ok(likeService.getAllLikes());
    }
    
    @DeleteMapping("/{id}")
    @Operation(summary = "删除点赞", description = "根据点赞ID删除点赞")
    @Parameter(name = "id", description = "点赞ID", required = true)
    public Result deleteLike(@PathVariable Long id) {
        likeService.deleteLike(id);
        return Result.ok();
    }
    
    @GetMapping("/post/{postId}")
    @Operation(summary = "获取帖子点赞", description = "获取指定帖子的所有点赞")
    @Parameter(name = "postId", description = "帖子ID", required = true)
    public Result getLikesByPostId(@PathVariable Long postId) {
        return Result.ok(likeService.getLikesByPostId(postId));
    }
    
    @GetMapping("/user/{userId}")
    @Operation(summary = "获取用户点赞", description = "获取指定用户的所有点赞")
    @Parameter(name = "userId", description = "用户ID", required = true)
    public Result getLikesByUserId(@PathVariable Long userId) {
        return Result.ok(likeService.getLikesByUserId(userId));
    }
    
    @Operation(summary = "获取点赞数", description = "获取帖子的点赞总数")
    @GetMapping("/post/{postId}/count")
    public Long getLikeCountByPostId(@Parameter(description = "帖子ID") @PathVariable Long postId) {
        return likeService.getLikeCountByPostId(postId);
    }
} 